#include "rook.h"

#include <QList>

Rook::Rook(Cell *cell, QString color, QWidget *parent): Piece(cell, color, parent){
    loadPieceImage(color + "rook");
    cell->setPiece(this);
}

QList<Cell *> Rook::getTips(Board *board)
{
    QList<Cell *> tips;
    Cell *c;
    for (int i=0; i<=7; i++) {
        c = isMove(i, 0, board);
        if (c == nullptr) break;
        if (c->hasPiece() && c != getCell()){
            if (c->getPiece()->getColor() != getColor()){
                tips << c;
            }
            break;
        }
        tips << c;
    }
    for (int i=0; i<=7; i++) {
        c = isMove(-i, 0, board);
        if (c == nullptr) break;
        if (c->hasPiece() && c != getCell()){
            if (c->getPiece()->getColor() != getColor()){
                tips << c;
            }
            break;
        }
        tips << c;
    }
    for (int i=0; i<=7; i++) {
        c = isMove(0, i, board);
        if (c == nullptr) break;
        if (c->hasPiece() && c != getCell()){
            if (c->getPiece()->getColor() != getColor()){
                tips << c;
            }
            break;
        }
        tips << c;
    }
    for (int i=0; i<=7; i++) {
        c = isMove(0, -i, board);
        if (c == nullptr) break;
        if (c->hasPiece() && c != getCell()){
            if (c->getPiece()->getColor() != getColor()){
                tips << c;
            }
            break;
        }
        tips << c;
    }
    return tips;
}
